layui.extend({
    selectN: '/layui_extends/selectN',
    selectM: '/layui_extends/selectM',
    baseConfig : "/js/pages/baseConfig"
}).use(['form','layer','table','element','util','baseConfig'],function(){

    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        baseConfig = layui.baseConfig,
        table = layui.table;
    var util = layui.util;

    var hideCol = true;
    if( baseConfig.checkPrivalege( baseConfig.CONSUMER_LIST_ALL)){
        hideCol = false;
    }
    var tableIns = table.render({
        elem: '#list',
        url : '/goods/list/',
        text: { none: "Aucun résultat"},
        cellMinWidth : 95,
        height : "full",
        page: true, //开启分页
        limit : 20,
        limits : [20,50,70,100],
        id : "listTable",
        cols : [[
            {field: 'jobNumber', title: "ID", align:"center"},
            {field: 'name', title: "Articles", width:300 ,align:"center", templet : function( d){
                return "<div style=\"overflow:hidden;white-space:nowrap;text-overflow:ellipsis;\">" + d.name + "</div>";
            }},
            {field: 'number', title: "Référence", align:"center"},
            {field: 'customHouse', title: "HS CODE", align:"center"},
            {field: 'status', title: "État", align:"center", templet : function( d){
                switch ( d.status) {
                    case "1": return "<span style='color: gray'>库存中</span>";
                    case "2": return "<span style=''>已销售等出关单</span>";
                    case "3": return "<span style='color: green'>已有出关单</span>";
                    default: return "<span style='color: gray'>库存中</span>";
                }
            }},
            {field: 'purePrice', title: 'HT ACHAT', align:'center', templet : function( d){
                return parseFloat( Math.abs( d.purePrice)).toFixed(2);
            }},
            {field: 'ratePrice', title: 'TVA', align:'center', templet : function( d){
                return parseFloat( Math.abs( d.ratePrice)).toFixed(2);
            }},
            {field: 'price', title: 'TTC', align:'center', templet : function( d){
                return parseFloat( Math.abs( d.price)).toFixed(2);
            }},
            {field: 'sellPrice', title: 'HT VENTE', align:'center', templet : function( d){
                return parseFloat( Math.abs( d.sellPrice)).toFixed(2);
            }},
        ]],
        response : {
            statusCode: 200 //规定成功的状态码，默认：0
        },
        parseData : function( res){ //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.count, //数据条数
                "data": res.data.data //解析数据列表
            };
        }
    });

    //搜索
    $("input[name=jobNumber]").on("input propertychange",function(e){
        search();
    });

    form.on("select(select_status)",function(){
        search();
    });

    function search(){
        var jobNumber = $("input[name=jobNumber]").val();
        var status = $("select[name=status]").val();
        table.reload("listTable",{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                "jobNumber": jobNumber,
                "status": status
            }
        })
    }
});
